import matplotlib.pyplot as pyp
import pylab
import csv

def opdracht1():
    pyp.plot([1,2,4,9,16,25,36,1])
    pyp.show()
opdracht1()

def opdracht2_3():
    pyp.title("Processorbelasting 07:00 - 18:00")
    pyp.plot([7,8,9,10,11,12,13,14,15,16,17,18],[10,10,10,30,20,25,30,35,70,75,80,10])
    pyp.xlabel("Tijd in uren")
    pyp.ylabel("CPU Belasting")
    pyp.axis([7,18,0,100])
    pyp.grid(True)
    pyp.annotate('Wat gebeurt hier?!', xy=(17,80), xytext=(15, 90), arrowprops=dict(facecolor='black', shrink=0.05))
    pyp.show()
opdracht2_3()

def opdracht4():
    pylab.figure(1, figsize=(6,6))
    pylab.axes([0.1, 0.1, 0.8, 0.8])

    labels = 'Win7', 'Vista', 'NT*', 'WinXP', 'Linux', 'MAC', 'Mobile'
    fracs = [56.8 , 3.0 , 1.8 , 22.1 , 4.8 , 9.2 , 1.8]
    explode=(0, 0, 0, 0, 0, 0, 0)

    pylab.pie(fracs, explode=explode, labels=labels, startangle=90)

    pylab.title('OS Platform statistics, oktober 2012')
    pylab.show()
opdracht4()

def opdracht5():
    #-------------------------------------------------------------------------------
    # Powershell script (Engels en Nederlands)
    # Get-Counter -Counter "\Processor(_Total)\% Processor Time" -SampleInterval 1 -MaxSamples 60 | export-counter d:\processors.csv -FileFormat csv
    # Get-Counter -Counter "\processor(_total)\percentage processortijd" -SampleInterval 1 -MaxSamples 60 | export-counter d:\processors.csv -FileFormat csv
    #-------------------------------------------------------------------------------
    res = csv.reader(open('D:\processors.csv'), delimiter=',')
    next(res) # Skip de eerste regel ((PDH-CSV 4.0) (W. Europe Standard Time)(-60),"\\bart-pc\processor(_total)\% processor time")
    next(res) # Skip de tweede regel (02/11/2014 12:52:08.041," ") -- Mist CPU belasting
    allebelasting = []
    for col in res:
        col[0] = col[0].split()
        datum = col[0][0]
        tijd = col[0][1]
        tijd = tijd[0:5]
        belasting = round(float(col[1]),1)
        allebelasting.append(belasting)

    pyp.title("Processorbelasting op " + datum + " " + tijd)
    pyp.plot(allebelasting)
    pyp.xlabel("Seconden")
    pyp.ylabel("CPU Belasting")
    pyp.axis([0,60,0,100])
    pyp.grid(True)
    pyp.show()
opdracht5()

